import type { RawDict } from '/#/store';
import {
  DeptListItem,
  DictParams,
  RoleListGetResultModel,
  RoleParams,
} from '/@/api/system/model/systemModel';
import { defHttp } from '/@/utils/http/axios';

enum Api {
  APP_LIST = '/system/app/list',
  IS_ACCOUNT_EXIST = '/system/user/checkExists',
  DEPT_LIST = '/system/dept/select',
  MENU_LIST = '/system/menu/tree-select',
  DICT_ITEM_LIST = '/system/dict-item/list',
  GET_ALL_ROLE_LIST = '/system/role/list',
}

export const getAppList = () => defHttp.get({ url: Api.APP_LIST });

export const getDictList = (params?: DictParams) =>
  defHttp.get<RawDict[]>({ url: Api.DICT_ITEM_LIST, params });

export const getDeptList = (params?: DeptListItem) => defHttp.get({ url: Api.DEPT_LIST, params });

export const getMenuTree = () => defHttp.get({ url: Api.MENU_LIST });

export const getAllRoleList = (params?: RoleParams) =>
  defHttp.get<RoleListGetResultModel>({ url: Api.GET_ALL_ROLE_LIST, params });

export const isAccountExist = (username: string) =>
  defHttp.get({ url: Api.IS_ACCOUNT_EXIST, params: { username } }, { errorMessageMode: 'none' });
